//
// Created by PC on 2024/2/27.
//

#include "arrUtil.h"
using namespace std;

vector<int> merge(vector<int> v, int l, int r, int m)
{
    vector<int> t;
    int i1 = l, i2 = m;
    while (i1 < m && i2 < r + 1)
    {
        if (v[i1] <= v[i2])
            t.push_back(v[i1++]);
        else
            t.push_back(v[i2++]);
    }
    for (; i1 < m; i1++) t.push_back(v[i1]);
    for (; i2 < r + 1; i2++) t.push_back(v[i2]);
    return t;
}


int main()
{
    vector<int> arr = {0, 2, 3, 8, 1, 4, 5, 7};
    vector<int> ret = merge(arr, 0, arr.size() - 1, 4);
    printVector(ret);
    return 0;
}